package com.sunday.aomi.ui.mine;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.TextView;

import com.sunday.common.base.BaseActivity;
import com.sunday.aomi.R;
import com.sunday.aomi.base.BaseApp;
import com.sunday.aomi.http.ApiClient;
import com.sunday.aomi.widgets.ShareWindow;
import com.sunday.member.http.MemberClient;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by 刘涛 on 2017/6/2.
 */

public class SpreadActivity extends BaseActivity {

    @Bind(R.id.title)
    TextView title;
    @Bind(R.id.right_txt)
    TextView rightTxt;
    @Bind(R.id.left_menu)
    ImageView leftMenu;
    @Bind(R.id.webview)
    WebView webview;
    private String shareUrl;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_spread);
        ButterKnife.bind(this);
        title.setText("分享好友");
        leftMenu.setVisibility(View.VISIBLE);
        rightTxt.setVisibility(View.VISIBLE);
        rightTxt.setText("分享");
        shareUrl= ApiClient.SHARE_URL+ String.valueOf(BaseApp.getInstance().getMember().getId());
        initWebView();
    }



    private void initWebView() {
//启用支持javascript
        WebSettings settings = webview.getSettings();
        settings.setJavaScriptEnabled(true);
        settings.setBuiltInZoomControls(false);
        settings.setSupportZoom(false);
        settings.setDomStorageEnabled(true);
        webview.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                if (!TextUtils.isEmpty(url)) {
                    view.loadUrl(url);
                } else {
                    dissMissDialog();
                }
                return true;
            }

            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
                dissMissDialog();
            }
        });
        webview.loadUrl(shareUrl);
    }

    @OnClick(R.id.right_txt)
    void share() {
        ShareWindow shareWindow=new ShareWindow(mContext,shareUrl,null,null,null);
        shareWindow.showPopupWindow(rightTxt);
    }
}
